package com.ease.actionscript.mapping.mapper;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 
 * @author nathanleewei
 * 
 */
public class IncludeRemotingClassesClassMapper extends ServiceManagerClassMapper {

	public static final String PREFIX_INCLUDEREMOTINGCLASSES = "IncludeRemotingClasses";

	private String className;

	private String serviceManagerClassName;

	private List<Class<?>> includeClassList;

	public void prepare() {

		String destinationProjectName = buildDestinationProjectName(this.getProjectName());

		// destinationPath = actionScriptMappingContext.getDestinationSourceFolder();
		className = PREFIX_INCLUDEREMOTINGCLASSES + camelProjectName(destinationProjectName);

		serviceManagerClassName = serviceManagerClassName(destinationProjectName);
		//

		// String destinationProjectName = this.getProjectName().replaceAll(".java.api", ".java").replaceAll(".java",
		// ".flex.remoting");

		destinationPath = actionScriptMappingContext.getFlexWorkspacePath() + "/" + destinationProjectName + "/src/";

		destinationFileName = className + ".as";
		// this.getActionScriptMappingContext().addIncludeClass(includeClass, destinationProjectName)
		//
		// this.addImportClassName("com.ease.flex.remoting."+className,this.projectName);

	}

	protected void optimize() {
		super.optimize();
		Set<Class<?>> includeClasses = this.getActionScriptMappingContext().getIncludeClasses(this.projectName);
		if (null != includeClasses) {
			includeClassList = new ArrayList<Class<?>>(includeClasses);
			sort(includeClassList);
			includeClassList = escapeEmpty(includeClassList);
		}

	}

	/**
	 * @return the includeClassList
	 */
	public List<Class<?>> getIncludeClassList() {
		return includeClassList;
	}

	/**
	 * @param includeClassList
	 *            the includeClassList to set
	 */
	public void setIncludeClassList(List<Class<?>> includeClassList) {
		this.includeClassList = includeClassList;
	}

	/**
	 * @return the className
	 */
	public String getClassName() {
		return className;
	}

	/**
	 * @param className
	 *            the className to set
	 */
	public void setClassName(String className) {
		this.className = className;
	}

	/**
	 * @return the serviceManagerClassName
	 */
	public String getServiceManagerClassName() {
		return serviceManagerClassName;
	}

	/**
	 * @param serviceManagerClassName
	 *            the serviceManagerClassName to set
	 */
	public void setServiceManagerClassName(String serviceManagerClassName) {
		this.serviceManagerClassName = serviceManagerClassName;
	}

}
